<?php
include($folder.'/layouts/code-behind/backend.php');
if ($_POST['isPostBack']!=='yes')
{
	if ($_GET['id'] !== null && $_GET['id'] !== '')
	{
		$_POST['main'] = queryOneRow('SELECT id,name,gallery_id FROM gallery WHERE id=:id', array('id'=>(int)$_GET['id']));
	}
}
$_POST['galleries']['dataSource'] = query('SELECT id AS `key`,name AS `value` FROM gallery WHERE gallery_id IS NULL', null);

function blc_pictures_in_gallery_select($from, $itemsPerPage, $galleryID)
{
	return query(
		'SELECT 
				gp.gallery_id AS galleryID, 
				gp.picture_id AS pictureID, 
				g.name AS galleryName, 
				p.name AS pictureName, 
				gp.text AS description 
			FROM gallery_picture AS gp 
			LEFT OUTER JOIN gallery AS g ON gp.gallery_id = g.id 
			LEFT OUTER JOIN picture AS p ON gp.picture_id = p.id 
			WHERE g.id=:id LIMIT :from,:itemsPerPage',
		array('id'=>(int)$galleryID,'from'=>$from,'itemsPerPage'=>$itemsPerPage));
}
function blc_pictures_in_gallery_select_count($galleryID)
{
	return queryScalar('SELECT COUNT(*) FROM gallery_picture WHERE gallery_id=:id', array('id'=>$galleryID));
}
$master['action'] = 'gallery_update';
$master['attributes'] = null;
$master['pageTitle'] = 'Galéria szerkesztése';
?>